package ar.edu.unq.wannaplay.roles;

import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.panel.Panel;

import ar.edu.unq.wannaplay.dtos.ClientDTO;
import ar.edu.unq.wannaplay.dtos.EmployeeDTO;
import ar.edu.unq.wannaplay.dtos.ProjectDTO;
import ar.edu.unq.wannaplay.pages.Home;
import ar.edu.unq.wannaplay.pages.client.EditClientPage;
import ar.edu.unq.wannaplay.pages.client.NewClientPage;
import ar.edu.unq.wannaplay.pages.client.SingleClientViewPage;
import ar.edu.unq.wannaplay.pages.employee.EditEmployeePage;
import ar.edu.unq.wannaplay.pages.employee.EmployeesViewPage;
import ar.edu.unq.wannaplay.pages.employee.NewEmployeePage;
import ar.edu.unq.wannaplay.pages.employee.SingleEmployeeViewPage;
import ar.edu.unq.wannaplay.pages.project.EditProjectPage;
import ar.edu.unq.wannaplay.pages.project.NewProjectPage;
import ar.edu.unq.wannaplay.pages.project.ProjectsViewPage;
import ar.edu.unq.wannaplay.pages.project.SingleProjectViewPage;
import ar.edu.unq.wannaplay.panels.RegisterPanel;
import ar.edu.unq.wannaplay.panels.client.ClientViewPanel;
import ar.edu.unq.wannaplay.panels.employee.EmployeesViewPanel;
import ar.edu.unq.wannaplay.panels.project.ProjectsViewPanel;
import ar.edu.unq.wannaplay.utils.ClientListView;
import ar.edu.unq.wannaplay.utils.DeleteLink;
import ar.edu.unq.wannaplay.utils.EmployeeListView;
import ar.edu.unq.wannaplay.utils.ProjectsListView;
import ar.edu.unq.wannaplay.utils.WPLink;
import ar.edu.unq.wannaplay.utils.WPLinkCreatedPage;

public class AdminLinkAdderStrategy extends AbstractLinkAdderStrategy {

    private static final long serialVersionUID = 1L;

    @Override
    public void addClientCreateLinks(final ClientViewPanel aPanel) {
        aPanel.add(this.createLinkPanel("createClientLink", new WPLink(LINK, NewClientPage.class), "link.panel.create",
                aPanel));
    }

    @Override
    public void addEmployeesViewLinks(final ListItem<EmployeeDTO> item, final EmployeeListView view, final Panel aPanel) {
        item.add(this.createLinkPanel(LINK,
                new WPLinkCreatedPage(LINK, new SingleEmployeeViewPage(item.getModelObject())), "link.panel.view",
                aPanel));
        item.add(this.createLinkPanel("delete",
                new DeleteLink<EmployeeDTO>(LINK, item.getModelObject(), view.getService(), EmployeesViewPage.class),
                "link.panel.delete", aPanel));
        item.add(this.createLinkPanel("modify", new WPLinkCreatedPage(LINK, new EditEmployeePage(item.getModelObject(),
                view.getService())), "link.panel.edit", aPanel));

    }

    @Override
    public void addEmployeeCreateLink(final EmployeesViewPanel aPanel) {
        aPanel.add(this.createLinkPanel("createEmployeeLink", new WPLink(LINK, NewEmployeePage.class),
                "link.panel.create", aPanel));
    }

    @Override
    public void addProjectsViewLinks(final ListItem<ProjectDTO> item, final ProjectsListView view, final Panel panel) {
        item.add(this.createLinkPanel(LINK, new WPLinkCreatedPage(LINK,
                new SingleProjectViewPage(item.getModelObject())), "link.panel.view", panel));

        item.add(this.createLinkPanel("delete",
                new DeleteLink<ProjectDTO>(LINK, item.getModelObject(), view.getService(), ProjectsViewPage.class),
                "link.panel.delete", panel));
        item.add(this.createLinkPanel("modify", new WPLinkCreatedPage(LINK, new EditProjectPage(item.getModelObject(),
                view.getService())), "link.panel.edit", panel));
    }

    @Override
    public void addProjectsCreateLink(final ProjectsViewPanel aPanel) {
        aPanel.add(this.createLinkPanel("createProjectLink", new WPLink(LINK, NewProjectPage.class),
                "link.panel.create", aPanel));
    }

    @Override
    public void addHomeContent(final Home home) {
        home.add(new RegisterPanel("mainContent", this.getService(), home.getFeedBackPanel()));
    }

    @Override
    public void addClientViewLinks(final ListItem<ClientDTO> item, final ClientListView view, final Panel panel) {
        item.add(this.createLinkPanel(LINK,
                new WPLinkCreatedPage(LINK, new SingleClientViewPage(item.getModelObject())), "link.panel.view", panel));
        item.add(this.createLinkPanel("modify", new WPLinkCreatedPage(LINK, new EditClientPage(item.getModelObject(),
                view.getService())), "link.panel.edit", panel));
    }
}
